package com.yufei.infoExtractor.jsEngine;

import java.io.IOException;

import java.net.MalformedURLException;

import javax.script.ScriptException;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class JsEngin {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws MalformedURLException 
	 * @throws FailingHttpStatusCodeException 
	 * @throws ScriptException 
	 * @throws NoSuchMethodException 
	 */
	public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {

		
		    final WebClient webClient = new WebClient();
		   webClient.getBrowserVersion().setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.2)Gecko/2008070208 Firefox/3.0.1");    
		    webClient.getCookieManager().clearCookies();

		   webClient.setJavaScriptEnabled(false);
		    //webClient.waitForBackgroundJavaScriptStartingBefore(10000);


		    // Get the first page
		    final HtmlPage page1 = webClient.getPage("http://www.baidu.com/link?url=bed99b09f3231513406dbe09f497a989cfe5db95200099a225d88982fe894b353955bffd5f8db48862f710a169f3d74458b65d43a96e94aafd50f6f61e2859568c3474d4c8f1e285fc3773f0c4fece5c654724412ac48371b66a1f0ea3a4c13dcd454228114ad3cffe07c3fe830b63e328fe2ff594aa9c25572a4edd0ef15caaa060ae4278d44f7cb752afa2388384e8a2cdb752b44730a7eb515a4e607efb30e05d847881ef463448df02b5c2f1aad524a5505699ed2a4581b766bf1dd46bfc9bc1340324d542e23df7c61356c0022c325c08bda3a7b38fde4d8c2e771d91f3b99b60b24e8bc2147c1f9abe1beb639117c592df3f71e19a7a3a01d1d10cae9193470aa7bd988da4e32d991baa69d62021da9148b4b0f2a518a024fa64524421a9a043da8217d594cd4353cab7bc0b189a23dcd0a9e9bba4ce1e89ab06ac7675783d2b1c7a276354be22043c5b0a058d410f89123be7df9dec2782629969ebac5573358cc3c0659257bfcf547131cdc0ebb0773dbb1416254fd865f4583a20e12cfc66b73acdaf18b3");

//System.out.print(page1.asXml());
		    // Get the form that we are dealing with and within that form, 
		    // find the submit button and the field that we want to change.
		 /*   final HtmlForm form = page1.getForms().get(0);
       
		    final HtmlSubmitInput button = form.getElementById("login_btn");
		    final HtmlTextInput userName = form.getElementById("u");
		    final HtmlPasswordInput password = form.getElementById("p");


		    // Change the value of the text field
		    userName.setValueAttribute("625070193");
		    password.setValueAttribute("15210834071afe");
		    // Now submit the form by clicking the button and get back the second page.
		    final HtmlPage page2 = button.click();*/
		  System.out.print(page1.asXml());

		    webClient.closeAllWindows();
		}
	

}
